#!/usr/bin/perl -w
#
#

use strict;
use warnings;

use lib qw(../../lib);

use Config::General;
use DBI;

my %cfg = Config::General->new('d:/www/MTT/mtt.conf')->getall();
#my %cfg = Config::General->new('/home/asan/dev/MTT/mtt.conf')->getall();

my $ci = $cfg{StatDB}->{connect_info};
my $dbh = DBI->connect(
	$ci->{dsn},
	$ci->{user},
	$ci->{password}
) || die DBI->errstr;
$dbh->do( $ci->{on_connect_do} );
	
my $table_name = $ARGV[0];

$dbh->do('DROP TABLE IF EXISTS ' . $table_name);
$dbh->do('CREATE TABLE ' . $table_name . '('
	. '
	`id` INT NOT NULL AUTO_INCREMENT,
	`switch` VARCHAR(10) DEFAULT NULL,
	`trunk` VARCHAR(20) DEFAULT NULL,
	`date`  datetime,
	`direction` VARCHAR(10) DEFAULT NULL,
	`a_mask` VARCHAR(13) DEFAULT NULL,
	`b_mask` VARCHAR(13) DEFAULT NULL,
	`NDEV` INT UNSIGNED DEFAULT NULL,
	`NBLOCKDEV` INT UNSIGNED DEFAULT NULL,
	`date_first` DATETIME DEFAULT NULL,
	`quarter_first` TINYINT UNSIGNED DEFAULT NULL,
	`MATTEMPTBHCA_first` INT UNSIGNED DEFAULT NULL,
	`NANSW_first` INT UNSIGNED  DEFAULT NULL,
	`NSEIZREQ_first` INT UNSIGNED DEFAULT NULL,
	`NCONVSEC_first` INT UNSIGNED DEFAULT NULL,
	`AVGNCONVSEC_first` INT UNSIGNED DEFAULT NULL,
	`ASR_first` INT UNSIGNED,
	`NER_first` VARCHAR(5) DEFAULT NULL,
	`date_second` DATETIME DEFAULT NULL,
	`quarter_second` TINYINT UNSIGNED DEFAULT NULL,
	`MATTEMPTBHCA_second` INT UNSIGNED DEFAULT NULL,
	`NANSW_second` INT UNSIGNED  DEFAULT NULL,
	`NSEIZREQ_second` INT UNSIGNED DEFAULT NULL,
	`NCONVSEC_second` INT UNSIGNED DEFAULT NULL,
	`AVGNCONVSEC_second` INT UNSIGNED DEFAULT NULL,
	`ASR_second` INT UNSIGNED,
	`NER_second` VARCHAR(5) DEFAULT NULL,
	KEY `date_key` (`date`),
	KEY `switch` (`switch`),
	KEY `trunk` (`trunk`(15)),
	KEY `b_mask` (`b_mask`),
	KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;'
);

$dbh->do('INSERT INTO ' . $table_name . q( VALUES(DEFAULT, 'MSKV', '89.28.160.5', '2010-12-13 23:00:00', 'in', '777', '999',123, 233, '2010-12-13 21:00:00', 1, 33, 42, 42, 42, 42, 555, '42', '2010-12-05 23:00:00', 
											3, 42, 42, 42, 42, 42, 55, '42')) );
$dbh->do('INSERT INTO ' . $table_name . q( VALUES(DEFAULT, 'ARHL', '89.28.160.5', '2010-12-13 23:00:00', 'in', '777', '999',123, 233, '2010-12-13 21:00:00', 1, 33, 42, 42, 42, 42, 555, '42', '2010-12-05 23:00:00', 
											3, 42, 42, 42, 42, 42, 55, '42')) );
